#include <string.h>

#include "Ray.h"

Ray::Ray( int memorySize )
{
    _memorySize = memorySize;
    
    if (memorySize != 0)
    {
        _testedObjects = new int[_memorySize];
        memset( _testedObjects, -1, _memorySize * sizeof( int ) );
    }
    else
    {
        _testedObjects = 0;
    }
    
    _lastPosition = 0;
}



Ray::Ray( const Ray& copy )
{
    _memorySize = copy._memorySize;
    
    _testedObjects = new int[_memorySize];
    for (int i = 0; i < _memorySize; ++i)
    {
        _testedObjects[i] = copy._testedObjects[i];
    }
    
    _lastPosition = copy._lastPosition;
    
    origin = copy.origin;
    direction = copy.direction;
}



Ray::~Ray()
{
    delete[] _testedObjects;
}



bool Ray::isInMemory( int objectID )
{
    for (int i = 0; i < _memorySize; ++i)
    {
        if (objectID == _testedObjects[i]) return true;
    }
    
    return false;
}



void Ray::addToMemory( int objectID )
{
    if( _memorySize == 0 ) return;
    
    _testedObjects[_lastPosition] = objectID;
    _lastPosition++;
    if (_lastPosition >= _memorySize) _lastPosition = 0;
}
